package com.example.email.controller;

import com.example.email.dtos.EmailDtos;
import com.example.email.entity.User;
import com.example.email.service.MailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.text.ParseException;

@Controller
public class MailController {
    @Autowired
    MailService mailService;

    @GetMapping("/receiptBox")
    public String toReceiptBox(Model model, HttpSession session,
                               @RequestParam(required = false,defaultValue = "1") Integer pageIndex,
                               @RequestParam(required = false,defaultValue = "5")  Integer pageSize) throws ParseException {
        User user= (User) session.getAttribute("user");
        //收件箱
        EmailDtos emailDtos=new EmailDtos();
        //分页集合
        model.addAttribute("pageInfo",mailService.selectMailStatus0ByPage(user.getMailboxNo(),pageIndex,pageSize,emailDtos));

        model.addAttribute("emailDtos",emailDtos);
        //收件箱所有邮件数
        model.addAttribute("allCount",mailService.allCount(user.getMailboxNo()));
        //收件箱未读邮件数
        model.addAttribute("shouCount",mailService.shouCount(user.getMailboxNo()));

        return "/receiptBox";
    }
}
